package com.shd.edanpei.util;

import android.app.Activity;

import com.shd.edanpei.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class AcCollector {

    public static List<Activity> activityList = new ArrayList<>();

    public static int getPosition(Activity activity) {
        for (int i = 0; i < activityList.size(); i++) {
            if (activityList.get(i) == activity) {
                return i;
            }
        }
        return -1;
    }



    /**
     * 增加Activity
     *
     * @param activity
     */
    public static void addActivity(Activity activity) {
        activityList.add(activity);
    }


    /**
     * 移除指定Activity
     *
     * @param activity
     */
    public static void removeActivity(Activity activity) {
        activityList.remove(activity);
    }



    public static void removeActivity(int index) {
        activityList.get(index).finish();
    }

    /**
     * 移除所有Activity
     */
    public static void finishAll() {
        for (Activity activity : activityList) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }

    /**
     * 移除其他所有Activity
     *
     * @param ac
     */
    public static void finishOther(Activity ac) {
        for (Activity activity : activityList) {
            if (activity != ac) {
                activity.finish();
            }
        }
    }

    public static void finishActivity(BaseActivity ac){
        for (Activity activity : activityList) {
            if (activity == ac){
                activity.finish();
            }
        }
    }


}
